﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface;

namespace MaxStudio.Concrete.Server.Service
{
    public class RPTAdmixturePowderService : ServiceHandle, IRPTAdmixturePowder
    {
        #region IRPTAdmixturePowder Members

        public OperationResult<List<tb_RPT_AdmixturePowder>> GetAllAdmixturePowder()
        {
            OperationResult<List<tb_RPT_AdmixturePowder>> result = new OperationResult<List<tb_RPT_AdmixturePowder>>();
            List<tb_RPT_AdmixturePowder> list = new List<tb_RPT_AdmixturePowder>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAllAdmixturePowder();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_AdmixturePowder>> GetAdmixturePowderBySequence(string strSequence)
        {
            OperationResult<List<tb_RPT_AdmixturePowder>> result = new OperationResult<List<tb_RPT_AdmixturePowder>>();
            List<tb_RPT_AdmixturePowder> list = new List<tb_RPT_AdmixturePowder>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAdmixturePowderBySequence(strSequence);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_AdmixturePowder>> GetAdmixturePowderByFeedWeight(string strFeedWeight)
        {
            OperationResult<List<tb_RPT_AdmixturePowder>> result = new OperationResult<List<tb_RPT_AdmixturePowder>>();
            List<tb_RPT_AdmixturePowder> list = new List<tb_RPT_AdmixturePowder>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAdmixturePowderBySequence(strFeedWeight);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_AdmixturePowder>> GetAdmixturePowderByFeedDate(DateTime feedDate1, DateTime feedDate2)
        {
            OperationResult<List<tb_RPT_AdmixturePowder>> result = new OperationResult<List<tb_RPT_AdmixturePowder>>();
            List<tb_RPT_AdmixturePowder> list = new List<tb_RPT_AdmixturePowder>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAdmixturePowderByFeedDate(feedDate1, feedDate2);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_AdmixturePowder> GetAdmixturePowderById(int id)
        {
            ConcreteDaoDataContext dataContext = getDateContext();
            OperationResult<tb_RPT_AdmixturePowder> result = new OperationResult<tb_RPT_AdmixturePowder>();
            tb_RPT_AdmixturePowder admixturePowder;
            try
            {
                admixturePowder = dataContext.GetAdmixturePowderById(id);
                if (admixturePowder == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = admixturePowder;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_AdmixturePowder> CreateAdmixturePowder(tb_RPT_AdmixturePowder entity)
        {
            OperationResult<tb_RPT_AdmixturePowder> result = new OperationResult<tb_RPT_AdmixturePowder>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.CreateAdmixturePowder(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_AdmixturePowder> ModifyAdmixturePowder(tb_RPT_AdmixturePowder entity)
        {
            OperationResult<tb_RPT_AdmixturePowder> result = new OperationResult<tb_RPT_AdmixturePowder>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.ModifyAdmixturePowder(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_AdmixturePowder> DeleteAdmixturePowder(tb_RPT_AdmixturePowder entity)
        {
            OperationResult<tb_RPT_AdmixturePowder> result = new OperationResult<tb_RPT_AdmixturePowder>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.DeleteAdmixturePowder(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
